package com.yzf.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yzf.entity.Employee;
import com.yzf.entity.Idea;
import com.yzf.entity.Project;
import com.yzf.service.IdeaService;
import com.yzf.util.util.DateTimeUtil;
import com.yzf.util.util.StringUtil;
import com.yzf.util.web.ServletUtil;

public class NewIdeaServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletUtil.forword(request, response, "new_idea");
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		HttpSession session = ServletUtil.getSession(request);
		Employee em = (Employee)session.getAttribute("employee");
		Project project = (Project)session.getAttribute("project");
		
		Idea idea = new Idea();
		idea.setId(StringUtil.getId());
		idea.setContent(content);
		idea.setCreatetime(DateTimeUtil.getNow());
		idea.setEmployeeid(em.getId());
		idea.setProjectid(project.getId());
		idea.setTitle(title);
		
		IdeaService service = new IdeaService();
		service.save(idea);
		
		
		/*List<Idea> ideaList = service.findByPid(project.getId());
		
		session.setAttribute("ideaList", ideaList);*/
		
		ServletUtil.redirect(response, "ideaShow.jspx");
		
	}

}
